<!DOCTYPE html>
<!-- saved from url=(0083)file:///C:/Users/Cr2022/AppData/Local/Temp/crossnote2025329-20188-1hhfp1q.bstm.html -->
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Pre</title>
      
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      
      <link rel="stylesheet" href="./Pre_files/katex.min.css">
      
      
      
      
      
      <style>
      code[class*=language-],pre[class*=language-]{color:#333;background:0 0;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.4;-moz-tab-size:8;-o-tab-size:8;tab-size:8;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:.8em;overflow:auto;border-radius:3px;background:#f5f5f5}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal;background:#f5f5f5}.token.blockquote,.token.comment{color:#969896}.token.cdata{color:#183691}.token.doctype,.token.macro.property,.token.punctuation,.token.variable{color:#333}.token.builtin,.token.important,.token.keyword,.token.operator,.token.rule{color:#a71d5d}.token.attr-value,.token.regex,.token.string,.token.url{color:#183691}.token.atrule,.token.boolean,.token.code,.token.command,.token.constant,.token.entity,.token.number,.token.property,.token.symbol{color:#0086b3}.token.prolog,.token.selector,.token.tag{color:#63a35c}.token.attr-name,.token.class,.token.class-name,.token.function,.token.id,.token.namespace,.token.pseudo-class,.token.pseudo-element,.token.url-reference .token.variable{color:#795da3}.token.entity{cursor:help}.token.title,.token.title .token.punctuation{font-weight:700;color:#1d3e81}.token.list{color:#ed6a43}.token.inserted{background-color:#eaffea;color:#55a532}.token.deleted{background-color:#ffecec;color:#bd2c00}.token.bold{font-weight:700}.token.italic{font-style:italic}.language-json .token.property{color:#183691}.language-markup .token.tag .token.punctuation{color:#333}.language-css .token.function,code.language-css{color:#0086b3}.language-yaml .token.atrule{color:#63a35c}code.language-yaml{color:#183691}.language-ruby .token.function{color:#333}.language-markdown .token.url{color:#795da3}.language-makefile .token.symbol{color:#795da3}.language-makefile .token.variable{color:#183691}.language-makefile .token.builtin{color:#0086b3}.language-bash .token.keyword{color:#0086b3}pre[data-line]{position:relative;padding:1em 0 1em 3em}pre[data-line] .line-highlight-wrapper{position:absolute;top:0;left:0;background-color:transparent;display:block;width:100%}pre[data-line] .line-highlight{position:absolute;left:0;right:0;padding:inherit 0;margin-top:1em;background:hsla(24,20%,50%,.08);background:linear-gradient(to right,hsla(24,20%,50%,.1) 70%,hsla(24,20%,50%,0));pointer-events:none;line-height:inherit;white-space:pre}pre[data-line] .line-highlight:before,pre[data-line] .line-highlight[data-end]:after{content:attr(data-start);position:absolute;top:.4em;left:.6em;min-width:1em;padding:0 .5em;background-color:hsla(24,20%,50%,.4);color:#f4f1ef;font:bold 65%/1.5 sans-serif;text-align:center;vertical-align:.3em;border-radius:999px;text-shadow:none;box-shadow:0 1px #fff}pre[data-line] .line-highlight[data-end]:after{content:attr(data-end);top:auto;bottom:.4em}html body{font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif;font-size:16px;line-height:1.6;color:#333;background-color:#fff;overflow:initial;box-sizing:border-box;word-wrap:break-word}html body>:first-child{margin-top:0}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{line-height:1.2;margin-top:1em;margin-bottom:16px;color:#000}html body h1{font-size:2.25em;font-weight:300;padding-bottom:.3em}html body h2{font-size:1.75em;font-weight:400;padding-bottom:.3em}html body h3{font-size:1.5em;font-weight:500}html body h4{font-size:1.25em;font-weight:600}html body h5{font-size:1.1em;font-weight:600}html body h6{font-size:1em;font-weight:600}html body h1,html body h2,html body h3,html body h4,html body h5{font-weight:600}html body h5{font-size:1em}html body h6{color:#5c5c5c}html body strong{color:#000}html body del{color:#5c5c5c}html body a:not([href]){color:inherit;text-decoration:none}html body a{color:#08c;text-decoration:none}html body a:hover{color:#00a3f5;text-decoration:none}html body img{max-width:100%}html body>p{margin-top:0;margin-bottom:16px;word-wrap:break-word}html body>ol,html body>ul{margin-bottom:16px}html body ol,html body ul{padding-left:2em}html body ol.no-list,html body ul.no-list{padding:0;list-style-type:none}html body ol ol,html body ol ul,html body ul ol,html body ul ul{margin-top:0;margin-bottom:0}html body li{margin-bottom:0}html body li.task-list-item{list-style:none}html body li>p{margin-top:0;margin-bottom:0}html body .task-list-item-checkbox{margin:0 .2em .25em -1.8em;vertical-align:middle}html body .task-list-item-checkbox:hover{cursor:pointer}html body blockquote{margin:16px 0;font-size:inherit;padding:0 15px;color:#5c5c5c;background-color:#f0f0f0;border-left:4px solid #d6d6d6}html body blockquote>:first-child{margin-top:0}html body blockquote>:last-child{margin-bottom:0}html body hr{height:4px;margin:32px 0;background-color:#d6d6d6;border:0 none}html body table{margin:10px 0 15px 0;border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}html body table th{font-weight:700;color:#000}html body table td,html body table th{border:1px solid #d6d6d6;padding:6px 13px}html body dl{padding:0}html body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:700}html body dl dd{padding:0 16px;margin-bottom:16px}html body code{font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:.85em;color:#000;background-color:#f0f0f0;border-radius:3px;padding:.2em 0}html body code::after,html body code::before{letter-spacing:-.2em;content:'\00a0'}html body pre>code{padding:0;margin:0;word-break:normal;white-space:pre;background:0 0;border:0}html body .highlight{margin-bottom:16px}html body .highlight pre,html body pre{padding:1em;overflow:auto;line-height:1.45;border:#d6d6d6;border-radius:3px}html body .highlight pre{margin-bottom:0;word-break:normal}html body pre code,html body pre tt{display:inline;max-width:initial;padding:0;margin:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}html body pre code:after,html body pre code:before,html body pre tt:after,html body pre tt:before{content:normal}html body blockquote,html body dl,html body ol,html body p,html body pre,html body ul{margin-top:0;margin-bottom:16px}html body kbd{color:#000;border:1px solid #d6d6d6;border-bottom:2px solid #c7c7c7;padding:2px 4px;background-color:#f0f0f0;border-radius:3px}@media print{html body{background-color:#fff}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{color:#000;page-break-after:avoid}html body blockquote{color:#5c5c5c}html body pre{page-break-inside:avoid}html body table{display:table}html body img{display:block;max-width:100%;max-height:100%}html body code,html body pre{word-wrap:break-word;white-space:pre}}.markdown-preview{width:100%;height:100%;box-sizing:border-box}.markdown-preview ul{list-style:disc}.markdown-preview ul ul{list-style:circle}.markdown-preview ul ul ul{list-style:square}.markdown-preview ol{list-style:decimal}.markdown-preview ol ol,.markdown-preview ul ol{list-style-type:lower-roman}.markdown-preview ol ol ol,.markdown-preview ol ul ol,.markdown-preview ul ol ol,.markdown-preview ul ul ol{list-style-type:lower-alpha}.markdown-preview .newpage,.markdown-preview .pagebreak{page-break-before:always}.markdown-preview pre.line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}.markdown-preview pre.line-numbers>code{position:relative}.markdown-preview pre.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:1em;font-size:100%;left:0;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-preview pre.line-numbers .line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.markdown-preview pre.line-numbers .line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}.markdown-preview .mathjax-exps .MathJax_Display{text-align:center!important}.markdown-preview:not([data-for=preview]) .code-chunk .code-chunk-btn-group{display:none}.markdown-preview:not([data-for=preview]) .code-chunk .status{display:none}.markdown-preview:not([data-for=preview]) .code-chunk .output-div{margin-bottom:16px}.markdown-preview .md-toc{padding:0}.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link{display:inline;padding:.25rem 0}.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link div,.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link p{display:inline}.markdown-preview .md-toc .md-toc-link-wrapper.highlighted .md-toc-link{font-weight:800}.scrollbar-style::-webkit-scrollbar{width:8px}.scrollbar-style::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}.scrollbar-style::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,.66);border:4px solid rgba(150,150,150,.66);background-clip:content-box}html body[for=html-export]:not([data-presentation-mode]){position:relative;width:100%;height:100%;top:0;left:0;margin:0;padding:0;overflow:auto}html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{position:relative;top:0;min-height:100vh}@media screen and (min-width:914px){html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{padding:2em calc(50% - 457px + 2em)}}@media screen and (max-width:914px){html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for=html-export]:not([data-presentation-mode]) .markdown-preview{font-size:14px!important;padding:1em}}@media print{html body[for=html-export]:not([data-presentation-mode]) #sidebar-toc-btn{display:none}}html body[for=html-export]:not([data-presentation-mode]) #sidebar-toc-btn{position:fixed;bottom:8px;left:8px;font-size:28px;cursor:pointer;color:inherit;z-index:99;width:32px;text-align:center;opacity:.4}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] #sidebar-toc-btn{opacity:1}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc{position:fixed;top:0;left:0;width:300px;height:100%;padding:32px 0 48px 0;font-size:14px;box-shadow:0 0 4px rgba(150,150,150,.33);box-sizing:border-box;overflow:auto;background-color:inherit}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar{width:8px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,.66);border:4px solid rgba(150,150,150,.66);background-clip:content-box}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc a{text-decoration:none}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc{padding:0 16px}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link{display:inline;padding:.25rem 0}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link div,html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link p{display:inline}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper.highlighted .md-toc-link{font-weight:800}html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{left:300px;width:calc(100% - 300px);padding:2em calc(50% - 457px - 300px / 2);margin:0;box-sizing:border-box}@media screen and (max-width:1274px){html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for=html-export]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{width:100%}}html body[for=html-export]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .markdown-preview{left:50%;transform:translateX(-50%)}html body[for=html-export]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .md-sidebar-toc{display:none}
/* Please visit the URL below for more information: */
/*   https://shd101wyy.github.io/markdown-preview-enhanced/#/customize-css */

      </style>
      <!-- The content below will be included at the end of the <head> element. --><script type="text/javascript">
  document.addEventListener("DOMContentLoaded", function () {
    // your code here
  });
</script></head><body for="html-export">
    
    
      <div class="crossnote markdown-preview  ">
      
<h1 id="pre1-lab-代码与演进过程分析">Pre1 Lab 代码与演进过程分析 </h1>
<p><strong>组长：陈润 组员：张博</strong></p>
<hr>
<h2 id="第一部分-代码介绍与优缺点分析">第一部分 代码介绍与优缺点分析 </h2>
<p><strong>因为组内就只有两个人，所以就统一先做对比，最后再统一的给出优缺点分析和建议</strong></p>
<h3 id="源代码">源代码 </h3>
<p><strong>代码组成</strong> <em>省略了后缀.java</em><br>
<strong>类的命名与主要功能</strong></p>
<table>
<thead>
<tr>
<th style="text-align:center">成员一的代码</th>
<th style="text-align:center">主要功能</th>
<th style="text-align:center">成员二的代码</th>
<th style="text-align:center">主要功能</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center">NewChessGame</td>
<td style="text-align:center">主程序入口，负责游戏的启动(创建 start 方法)和主循环逻辑</td>
<td style="text-align:center">App</td>
<td style="text-align:center">主程序入口，通过 GameManager 类创建一个 gamemanager 实例并启动游戏循环</td>
</tr>
<tr>
<td style="text-align:center">ChessBoard</td>
<td style="text-align:center">基础棋盘类，棋盘的初始化和落子逻辑</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">Chess</td>
<td style="text-align:center">定义棋盘和棋子的常量</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">Player</td>
<td style="text-align:center">管理玩家名称及当前玩家状态，提供玩家切换功能</td>
<td style="text-align:center">Player</td>
<td style="text-align:center">表示玩家信息及棋子符号</td>
</tr>
<tr>
<td style="text-align:center">Game</td>
<td style="text-align:center">抽象父类，定义游戏基础属性和方法(如初始化棋盘、落子验证、游戏结束判定)</td>
<td style="text-align:center">Board</td>
<td style="text-align:center">抽象父类，定义棋盘游戏的通用逻辑，包含抽象方法和基础属性</td>
</tr>
<tr>
<td style="text-align:center">PeaceGame</td>
<td style="text-align:center">Game 的子类，实现 peace 模式</td>
<td style="text-align:center">PeaceBoard</td>
<td style="text-align:center">Board 的子类，实现 peace 模式</td>
</tr>
<tr>
<td style="text-align:center">ReversiGame</td>
<td style="text-align:center">Game 的子类，实现 reversi 模式</td>
<td style="text-align:center">ReversiBoard</td>
<td style="text-align:center">Board 的子类，实现 reversi 模式</td>
</tr>
<tr>
<td style="text-align:center">GomokuGame</td>
<td style="text-align:center">Game 的子类，实现 Gomoku 模式</td>
<td style="text-align:center">Five_keyBoard</td>
<td style="text-align:center">Board 的子类，实现 Five_key 模式</td>
</tr>
<tr>
<td style="text-align:center">Displayboard</td>
<td style="text-align:center">游戏时的处理棋盘显示和用户输入解析</td>
<td style="text-align:center"></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td style="text-align:center">GameManager</td>
<td style="text-align:center">管理多个游戏实例的创建、切换和存储</td>
<td style="text-align:center">GameManager</td>
<td style="text-align:center">创建多个游戏，控制多局游戏的切换</td>
</tr>
</tbody>
</table>
<h3 id="代码主要功能差异">代码主要功能差异 </h3>
<ol>
<li>
<p>父类的选择</p>
<ul>
<li>成员 1 的抽象父类为 <code>Game</code>，子类为 <code>PeaceGame</code> 等。
<blockquote>
<p>父类提供公共方法，定义游戏的通用方法和变量，各个子类单独处理自己的游戏逻辑（规则），初始化各自的棋盘状态。</p>
</blockquote>
</li>
</ul>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-class">class</span> <span class="token class-name">Game</span> <span class="token punctuation">{</span>
<span class="token comment">// protect 仅父类与子类可用</span>
<span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-char">char</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span> board<span class="token punctuation">;</span>
<span class="token keyword keyword-protected">protected</span> <span class="token class-name">Player</span> player<span class="token punctuation">;</span>
<span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-int">int</span> gameId<span class="token punctuation">;</span>
<span class="token keyword keyword-protected">protected</span> <span class="token class-name">String</span> mode<span class="token punctuation">;</span>
<span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-int">int</span> round<span class="token punctuation">;</span> <span class="token comment">// Gomoku专用：记录当前轮数</span>
<span class="token keyword keyword-protected">protected</span> <span class="token class-name">List</span><span class="token operator">&lt;</span><span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">&gt;</span> legalMoves <span class="token operator">=</span> <span class="token keyword keyword-new">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword keyword-public">public</span> <span class="token class-name">Game</span><span class="token punctuation">(</span><span class="token class-name">String</span> player1<span class="token punctuation">,</span> <span class="token class-name">String</span> player2<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> gameId<span class="token punctuation">,</span> <span class="token class-name">String</span> mode<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword keyword-this">this</span><span class="token punctuation">.</span>player <span class="token operator">=</span> <span class="token keyword keyword-new">new</span> <span class="token class-name">Player</span><span class="token punctuation">(</span>player1<span class="token punctuation">,</span> player2<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword keyword-this">this</span><span class="token punctuation">.</span>gameId <span class="token operator">=</span> gameId<span class="token punctuation">;</span>
    <span class="token keyword keyword-this">this</span><span class="token punctuation">.</span>mode <span class="token operator">=</span> mode<span class="token punctuation">;</span>
    <span class="token function">initializeBoard</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-void">void</span> <span class="token function">initializeBoard</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">isValidMove</span><span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> row<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> col<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">placeChess</span><span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> row<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> col<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">isGameOver</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token class-name">String</span> <span class="token function">getScoreInfo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">// 新增方法（Gomoku需要）</span>
<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-int">int</span> <span class="token function">getRound</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword keyword-return">return</span> round<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-char">char</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">getBoard</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword keyword-return">return</span> board<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// reversi需要</span>
<span class="token keyword keyword-public">public</span> <span class="token class-name">List</span><span class="token operator">&lt;</span><span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">&gt;</span> <span class="token function">getLegalMoves</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword keyword-return">return</span> legalMoves<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword keyword-public">public</span> <span class="token class-name">String</span> <span class="token function">getMode</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword keyword-return">return</span> mode<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-int">int</span> <span class="token function">getGameId</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword keyword-return">return</span> gameId<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword keyword-public">public</span> <span class="token class-name">Player</span> <span class="token function">getPlayer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword keyword-return">return</span> player<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre><ul>
<li>成员 2 的抽象父类为 <code>Board，子类为 PeaceBoard</code> 等。
<blockquote>
<p>与之前不同的是 Board 中还包含了打印棋盘和不同游戏模式的提示信息的功能。</p>
</blockquote>
</li>
</ul>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-class">class</span> <span class="token class-name">Board</span> <span class="token punctuation">{</span>
 <span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-static">static</span> <span class="token keyword keyword-final">final</span> <span class="token keyword keyword-char">char</span> <span class="token constant">EMPTY</span> <span class="token operator">=</span> <span class="token char">'·'</span><span class="token punctuation">;</span>
 <span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-static">static</span> <span class="token keyword keyword-final">final</span> <span class="token keyword keyword-char">char</span> <span class="token constant">BLACK</span> <span class="token operator">=</span> <span class="token char">'●'</span><span class="token punctuation">;</span>
 <span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-static">static</span> <span class="token keyword keyword-final">final</span> <span class="token keyword keyword-char">char</span> <span class="token constant">WHITE</span> <span class="token operator">=</span> <span class="token char">'○'</span><span class="token punctuation">;</span>
 <span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-static">static</span> <span class="token keyword keyword-final">final</span> <span class="token keyword keyword-char">char</span> <span class="token constant">LEGAL_MOVE</span> <span class="token operator">=</span> <span class="token char">'+'</span><span class="token punctuation">;</span>

 <span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-char">char</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span> grid<span class="token punctuation">;</span>
 <span class="token keyword keyword-protected">protected</span> <span class="token class-name">Player</span> player1<span class="token punctuation">;</span>
 <span class="token keyword keyword-protected">protected</span> <span class="token class-name">Player</span> player2<span class="token punctuation">;</span>
 <span class="token keyword keyword-protected">protected</span> <span class="token class-name">Player</span> currentPlayer<span class="token punctuation">;</span>
 <span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-boolean">boolean</span> gameOver<span class="token punctuation">;</span>

 <span class="token keyword keyword-public">public</span> <span class="token class-name">Board</span><span class="token punctuation">(</span><span class="token class-name">String</span> player1Name<span class="token punctuation">,</span> <span class="token class-name">String</span> player2Name<span class="token punctuation">)</span> <span class="token punctuation">{</span>
     grid <span class="token operator">=</span> <span class="token keyword keyword-new">new</span> <span class="token keyword keyword-char">char</span><span class="token punctuation">[</span><span class="token number">8</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token number">8</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
     player1 <span class="token operator">=</span> <span class="token keyword keyword-new">new</span> <span class="token class-name">Player</span><span class="token punctuation">(</span>player1Name<span class="token punctuation">,</span> <span class="token constant">BLACK</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     player2 <span class="token operator">=</span> <span class="token keyword keyword-new">new</span> <span class="token class-name">Player</span><span class="token punctuation">(</span>player2Name<span class="token punctuation">,</span> <span class="token constant">WHITE</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     currentPlayer <span class="token operator">=</span> player1<span class="token punctuation">;</span>
     gameOver <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
     <span class="token function">initializeBoard</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 <span class="token punctuation">}</span>

 <span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-void">void</span> <span class="token function">initializeBoard</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 <span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">makeMove</span><span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> row<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> col<span class="token punctuation">)</span><span class="token punctuation">;</span>
 <span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-void">void</span> <span class="token function">display</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

 <span class="token keyword keyword-public">public</span> <span class="token class-name">Player</span> <span class="token function">getCurrentPlayer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
     <span class="token keyword keyword-return">return</span> currentPlayer<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>

 <span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-void">void</span> <span class="token function">switchPlayer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
     currentPlayer <span class="token operator">=</span> <span class="token punctuation">(</span>currentPlayer <span class="token operator">==</span> player1<span class="token punctuation">)</span> <span class="token operator">?</span> player2 <span class="token operator">:</span> player1<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>

 <span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">isValidPosition</span><span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> row<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> col<span class="token punctuation">)</span> <span class="token punctuation">{</span>
     <span class="token keyword keyword-return">return</span> row <span class="token operator">&gt;=</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> row <span class="token operator">&lt;</span> <span class="token number">8</span> <span class="token operator">&amp;&amp;</span> col <span class="token operator">&gt;=</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> col <span class="token operator">&lt;</span> <span class="token number">8</span><span class="token punctuation">;</span>
 <span class="token punctuation">}</span>

 <span class="token keyword keyword-protected">protected</span> <span class="token class-name">List</span><span class="token operator">&lt;</span><span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">&gt;</span> <span class="token function">getLegalMoves</span><span class="token punctuation">(</span><span class="token class-name">Player</span> player<span class="token punctuation">)</span> <span class="token punctuation">{</span>

     <span class="token class-name">List</span><span class="token operator">&lt;</span><span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">&gt;</span> moves <span class="token operator">=</span> <span class="token keyword keyword-new">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">8</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
         <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> j <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> <span class="token number">8</span><span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
             <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>grid<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token constant">EMPTY</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                 moves<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword keyword-new">new</span> <span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">{</span>i<span class="token punctuation">,</span> j<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
             <span class="token punctuation">}</span>
         <span class="token punctuation">}</span>
     <span class="token punctuation">}</span>
     <span class="token keyword keyword-return">return</span> moves<span class="token punctuation">;</span>
 <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>

</code></pre></li>
</ol>
<hr>
<ol start="2">
<li>
<p>棋盘逻辑</p>
<ul>
<li>成员 1 ：<code>ChessBoard</code> 作为基础棋盘类，<code>Game</code> 负责游戏规则和状态。</li>
<li>成员 2 ：棋盘和游戏规则合并到 <code>Board</code> 子类中。</li>
</ul>
</li>
<li>
<p>显示与打印</p>
<ul>
<li>成员 1 ：<code>DisplayBoard</code> 独立处理界面显示和输入解析。</li>
<li>成员 2 ：<code>Board</code> 的子类（<code>PeaceBoard</code>、<code>ReversiBoard</code>、<code>Five_keyBoard</code>）直接实现 <code>display</code> 方法。</li>
</ul>
</li>
<li>
<p>管理</p>
<ul>
<li>都是由<code>GameManager</code>类进行管理，但二者略有不同。</li>
<li>成员 1 的 <code>GameManager</code> 管理 <code>Game</code> 对象，功能为多游戏切换和添加新游戏。</li>
<li>成员 2 的 <code>GameManager</code> 直接管理 <code>Board</code> 对象
<blockquote>
<p>功能有初始化三局游戏。<br>
支持添加新游戏、切换当前游戏、处理用户输入（落子、pass、退出等）。<br>
显示游戏信息和当前棋盘状态。<br>
处理特殊操作（<code>pass</code>,<code>quit</code>）。</p>
</blockquote>
</li>
</ul>
</li>
<li>
<p>关键代码介绍</p>
</li>
</ol>
<p><strong>成员一</strong></p>
<ul>
<li>五子棋胜利规则<code>GomokuGame.checkWin()</code></li>
</ul>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token comment">// 四个方向检查：水平、垂直、两条对角线 五子琪规则</span>
<span class="token keyword keyword-private">private</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">checkWin</span><span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> row<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> col<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword keyword-char">char</span> target <span class="token operator">=</span> board<span class="token punctuation">[</span>row<span class="token punctuation">]</span><span class="token punctuation">[</span>col<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span> directions <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token punctuation">{</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>

    <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> dir <span class="token operator">:</span> directions<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword keyword-int">int</span> count <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>
        <span class="token comment">// 正向检查</span>
        <span class="token keyword keyword-int">int</span> x <span class="token operator">=</span> row <span class="token operator">+</span> dir<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> y <span class="token operator">=</span> col <span class="token operator">+</span> dir<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token keyword keyword-while">while</span> <span class="token punctuation">(</span>x <span class="token operator">&gt;=</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> x <span class="token operator">&lt;</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">BOARD_SIZE</span> <span class="token operator">&amp;&amp;</span> y <span class="token operator">&gt;=</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> y <span class="token operator">&lt;</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">BOARD_SIZE</span> <span class="token operator">&amp;&amp;</span> board<span class="token punctuation">[</span>x<span class="token punctuation">]</span><span class="token punctuation">[</span>y<span class="token punctuation">]</span> <span class="token operator">==</span> target<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            count<span class="token operator">++</span><span class="token punctuation">;</span>
            x <span class="token operator">+=</span> dir<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
            y <span class="token operator">+=</span> dir<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token comment">// 反向检查</span>
        x <span class="token operator">=</span> row <span class="token operator">-</span> dir<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        y <span class="token operator">=</span> col <span class="token operator">-</span> dir<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token keyword keyword-while">while</span> <span class="token punctuation">(</span>x <span class="token operator">&gt;=</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> x <span class="token operator">&lt;</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">BOARD_SIZE</span> <span class="token operator">&amp;&amp;</span> y <span class="token operator">&gt;=</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> y <span class="token operator">&lt;</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">BOARD_SIZE</span> <span class="token operator">&amp;&amp;</span> board<span class="token punctuation">[</span>x<span class="token punctuation">]</span><span class="token punctuation">[</span>y<span class="token punctuation">]</span> <span class="token operator">==</span> target<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            count<span class="token operator">++</span><span class="token punctuation">;</span>
            x <span class="token operator">-=</span> dir<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
            y <span class="token operator">-=</span> dir<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>count <span class="token operator">&gt;=</span> <span class="token number">5</span><span class="token punctuation">)</span>
            <span class="token keyword keyword-return">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token keyword keyword-return">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><ul>
<li><code>reversi</code>检查是否存在可下棋的地方(<code>ReversiGame.isValidMove</code>)</li>
</ul>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token comment">//方向数组，8个方向</span>
<span class="token keyword keyword-private">private</span> <span class="token keyword keyword-static">static</span> <span class="token keyword keyword-final">final</span> <span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token constant">DIRECTIONS</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
            <span class="token punctuation">{</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">0</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token punctuation">{</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span> <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span> <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token annotation punctuation">@Override</span>
<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">isValidMove</span><span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> row<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> col<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token comment">// 检查目标位置是否为EMPTY，若不是则不能落子</span>
    <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>board<span class="token punctuation">[</span>row<span class="token punctuation">]</span><span class="token punctuation">[</span>col<span class="token punctuation">]</span> <span class="token operator">!=</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">EMPTY</span><span class="token punctuation">)</span>
        <span class="token keyword keyword-return">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
    <span class="token comment">// 确定当前玩家的棋子符号</span>
    <span class="token keyword keyword-char">char</span> currentSymbol <span class="token operator">=</span> player<span class="token punctuation">.</span><span class="token function">isCurrentPlayer1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">?</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">PLAYER1_SYMBOL</span> <span class="token operator">:</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">PLAYER2_SYMBOL</span><span class="token punctuation">;</span>
    <span class="token comment">// 遍历所有方向，检查是否存在符合翻转规则的方向</span>
    <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> dir <span class="token operator">:</span> <span class="token constant">DIRECTIONS</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span><span class="token function">checkDirection</span><span class="token punctuation">(</span>row<span class="token punctuation">,</span> col<span class="token punctuation">,</span> dir<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">,</span> dir<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">,</span> currentSymbol<span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword keyword-return">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span><span class="token comment">// 如果任意方向满足规则，则该位置为合法落子位置</span>
    <span class="token punctuation">}</span>
    <span class="token keyword keyword-return">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

    <span class="token comment">// 检查指定方向是否存在可翻转的棋子链</span>
    <span class="token keyword keyword-private">private</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">checkDirection</span><span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> row<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> col<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> dx<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> dy<span class="token punctuation">,</span> <span class="token keyword keyword-char">char</span> symbol<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword keyword-int">int</span> x <span class="token operator">=</span> row <span class="token operator">+</span> dx<span class="token punctuation">;</span>
        <span class="token keyword keyword-int">int</span> y <span class="token operator">=</span> col <span class="token operator">+</span> dy<span class="token punctuation">;</span>
        <span class="token keyword keyword-boolean">boolean</span> hasOpponent <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span><span class="token comment">// 标记是否遇到对手棋子</span>
        <span class="token comment">// 遍历当前方向，检查是否符合翻转规则</span>
        <span class="token keyword keyword-while">while</span> <span class="token punctuation">(</span>x <span class="token operator">&gt;=</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> x <span class="token operator">&lt;</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">BOARD_SIZE</span> <span class="token operator">&amp;&amp;</span> y <span class="token operator">&gt;=</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> y <span class="token operator">&lt;</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">BOARD_SIZE</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>board<span class="token punctuation">[</span>x<span class="token punctuation">]</span><span class="token punctuation">[</span>y<span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token class-name">Chess</span><span class="token punctuation">.</span><span class="token constant">EMPTY</span><span class="token punctuation">)</span>
                <span class="token keyword keyword-return">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span> <span class="token comment">// 遇到EMPTY，无法形成翻转链</span>
            <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>board<span class="token punctuation">[</span>x<span class="token punctuation">]</span><span class="token punctuation">[</span>y<span class="token punctuation">]</span> <span class="token operator">==</span> symbol<span class="token punctuation">)</span>
                <span class="token keyword keyword-return">return</span> hasOpponent<span class="token punctuation">;</span><span class="token comment">// 遇到自己的棋子，若之前有对手棋子则合法</span>
            hasOpponent <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span><span class="token comment">// 遇到对手棋子，继续检查</span>
            x <span class="token operator">+=</span> dx<span class="token punctuation">;</span>
            y <span class="token operator">+=</span> dy<span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
        <span class="token keyword keyword-return">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre><p><strong>成员二</strong></p>
<ul>
<li><code>reversi</code>寻找并储存可下位置</li>
</ul>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token keyword keyword-protected">protected</span> <span class="token class-name">List</span><span class="token operator">&lt;</span><span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">&gt;</span> <span class="token function">getLegalMoves</span><span class="token punctuation">(</span><span class="token class-name">Player</span> player<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token class-name">List</span><span class="token operator">&lt;</span><span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token operator">&gt;</span> moves <span class="token operator">=</span> <span class="token keyword keyword-new">new</span> <span class="token class-name">ArrayList</span><span class="token generics"><span class="token punctuation">&lt;</span><span class="token punctuation">&gt;</span></span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// 定义move,用于存储所有合法的落子位置</span>
    <span class="token keyword keyword-char">char</span> currentPiece <span class="token operator">=</span> player<span class="token punctuation">.</span><span class="token function">getPiece</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// 获取当前玩家的棋子符号</span>
    <span class="token keyword keyword-char">char</span> opponentPiece <span class="token operator">=</span> <span class="token punctuation">(</span>currentPiece <span class="token operator">==</span> <span class="token constant">BLACK</span><span class="token punctuation">)</span> <span class="token operator">?</span> <span class="token constant">WHITE</span> <span class="token operator">:</span> <span class="token constant">BLACK</span><span class="token punctuation">;</span>

    <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token number">8</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> j <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> <span class="token number">8</span><span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>grid<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">==</span> <span class="token constant">EMPTY</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">// 检查8个方向</span>
                <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> dx <span class="token operator">=</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span> dx <span class="token operator">&lt;=</span> <span class="token number">1</span><span class="token punctuation">;</span> dx<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> dy <span class="token operator">=</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span> dy <span class="token operator">&lt;=</span> <span class="token number">1</span><span class="token punctuation">;</span> dy<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                        <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>dx <span class="token operator">==</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> dy <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token keyword keyword-continue">continue</span><span class="token punctuation">;</span>

                        <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span><span class="token function">checkDirection</span><span class="token punctuation">(</span>i<span class="token punctuation">,</span> j<span class="token punctuation">,</span> dx<span class="token punctuation">,</span> dy<span class="token punctuation">,</span> currentPiece<span class="token punctuation">,</span> opponentPiece<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                            moves<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword keyword-new">new</span> <span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">{</span>i<span class="token punctuation">,</span> j<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                            <span class="token keyword keyword-break">break</span><span class="token punctuation">;</span> <span class="token comment">// 只要有一个方向合法即可</span>
                        <span class="token punctuation">}</span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token keyword keyword-return">return</span> moves<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><ul>
<li><code>GameManager</code>中对不同输入的处理</li>
</ul>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token keyword keyword-public">public</span> <span class="token keyword keyword-void">void</span> <span class="token function">start</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword keyword-while">while</span> <span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token function">clearScreen</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token function">displayCurrentGame</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"请玩家["</span> <span class="token operator">+</span> <span class="token function">getCurrentGame</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getCurrentPlayer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">"]输入落子位置(如1A) / "</span> <span class="token operator">+</span>
                    <span class="token string">"游戏编号(1-"</span> <span class="token operator">+</span> games<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">") / "</span> <span class="token operator">+</span>
                    <span class="token string">"新游戏类型(peace/reversi/gomoku) / "</span> <span class="token operator">+</span>
                    <span class="token string">"放弃行棋(pass) / "</span> <span class="token operator">+</span>
                    <span class="token string">"退出程序(quit):"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token class-name">String</span> input <span class="token operator">=</span> scanner<span class="token punctuation">.</span><span class="token function">nextLine</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

            <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>input<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"quit"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"游戏结束，谢谢游玩！"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token keyword keyword-break">break</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword keyword-else">else</span> <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>input<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"pass"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token function">handlePass</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword keyword-else">else</span> <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>input<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"peace"</span><span class="token punctuation">)</span> <span class="token operator">||</span> input<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"reversi"</span><span class="token punctuation">)</span> <span class="token operator">||</span> input<span class="token punctuation">.</span><span class="token function">equals</span><span class="token punctuation">(</span><span class="token string">"gomoku"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token function">addNewGame</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword keyword-else">else</span> <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span><span class="token function">isValidGameNumber</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token function">switchGame</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span> <span class="token keyword keyword-else">else</span> <span class="token punctuation">{</span>
                <span class="token function">handleMove</span><span class="token punctuation">(</span>input<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
</code></pre><hr>
<h3 id="优缺点分析">优缺点分析 </h3>
<h4 id="成员-1">成员 1 </h4>
<p><strong>优点</strong></p>
<ol>
<li>职责分离清晰：
<ul>
<li>抽象类 <code>Game</code> 负责游戏规则，<code>DisplayBoard</code> 独立处理界面显示。</li>
</ul>
</li>
<li>扩展性强：
<ul>
<li>通过继承 <code>Game</code> 实现不同模式（如 <code>GomokuGame</code>），新增模式只需扩展父类。</li>
</ul>
</li>
<li>命名规范：
<ul>
<li>类名如 <code>ReversiGame</code>、<code>GomokuGame</code> 明确表达功能，符合 OOP 设计原则。</li>
</ul>
</li>
</ol>
<p><strong>不足</strong></p>
<ul>
<li>显示模块依赖控制台：若迁移到图形化界面，需重构 <code>DisplayBoard</code> 的绘制逻辑。</li>
<li>示例：<code>DisplayBoard</code> 的 <code>printFullUI</code> 方法将棋盘与信息分栏显示。（逻辑对控制台依赖性太强，不利于图形化界面。）</li>
</ul>
<pre data-role="codeBlock" data-info="" class="language-text"><code>   A  B  C  D  E  F  G  H   当前游戏: #1
1  ·  ·  ·  ·  ·  ·  ·  ·   模式: peace
2  ·  ·  ·  ·  ·  ·  ·  ·   玩家: 张三
3  ·  ·  ·  ·  ·  ·  ·  ·
4  ·  ·  ·  ○  ●  ·  ·  ·
5  ·  ·  ·  ●  ○  ·  ·  ·   游戏列表:
6  ·  ·  ·  ·  ·  ·  ·  ·   1 . peace        2 . reversi
7  ·  ·  ·  ·  ·  ·  ·  ·   3 . gomoku
8  ·  ·  ·  ·  ·  ·  ·  ·

输入示例(坐标:1A 棋盘编号：1，2 添加模式(peace(黑白棋无规则)/reversi(黑白棋有规则))/gomoku(五子棋))
其他命令：pass(放弃此次下棋,仅限reversi)/quit(退出游戏)。
</code></pre><ul>
<li>五子棋胜利检测仍然需要改进：<code>GomokuGame</code> 的 <code>checkWin</code> 方法实际上只可以检测是否五子连珠的情况，无法进一步的考虑更多的胜利情况。</li>
<li>比如下面这种情况，玩家张三执白棋先行，此时李四已必然胜利，但程序无法检测这种情况，游戏仍然运行。</li>
</ul>
<pre data-role="codeBlock" data-info="" class="language-text"><code>输入（坐标:1A 棋盘编号：1，2 添加模式(peace(黑白棋无规则)/reversi(黑白棋有规则)/gomoku(五子棋))
其他命令：pass(放弃此次下棋,仅限reversi)/quit(退出游戏): 2e
A B C D E F G H   当前游戏: #3
1  . ● ● ● . . . .   模式: gomoku
2  . ○ ○ ○ ○ . . .   玩家: 张三
3  . . . ● . . . .   轮数: 8
4  . . . . . . . .
5  . . . . . . . .   游戏列表:
6  . . . . . . . .   1. peace
7  . . . . . . . .   2. reversi
8  . . . . . . . .   3. gomoku

输入（坐标:1A 棋盘编号：1，2 添加模式(peace(黑白棋无规则)/reversi(黑白棋有规则)/gomoku(五子棋))
其他命令：pass(放弃此次下棋,仅限 reversi)/quit(退出游戏):

</code></pre><h4 id="成员-2">成员 2 </h4>
<p><strong>优点</strong></p>
<ol>
<li>良好的面向对象设计：</li>
</ol>
<ul>
<li>使用了抽象类<code>Board</code>作为基类，其他游戏类型继承它，实现了代码复用</li>
<li>合理的类划分（<code>Board</code>, <code>Player</code>, <code>GameManager</code>等）体现了单一职责原则</li>
</ul>
<ol start="2">
<li>灵活的输入处理：</li>
</ol>
<ul>
<li>支持多种输入方式：落子、切换游戏、添加新游戏、pass、退出等</li>
<li>对输入进行了验证和错误处理</li>
</ul>
<ol start="3">
<li>清晰的用户界面：</li>
</ol>
<ul>
<li>提供了直观的 ASCII 图形界面显示棋盘</li>
<li>显示当前玩家、游戏编号等信息</li>
</ul>
<p><strong>不足</strong>：</p>
<ol>
<li>代码重复：</li>
</ol>
<ul>
<li>多个<code>Board</code>子类中有重复的<code>isBoardFull()、display</code>等方法，可以提到父类中</li>
<li>显示玩家信息的代码在多个子类中重复</li>
</ul>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token comment">// 在board父类中定义了抽象方法</span>
<span class="token keyword keyword-protected">protected</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-void">void</span> <span class="token function">initializeBoard</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">makeMove</span><span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> row<span class="token punctuation">,</span> <span class="token keyword keyword-int">int</span> col<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword keyword-public">public</span> <span class="token keyword keyword-abstract">abstract</span> <span class="token keyword keyword-void">void</span> <span class="token function">display</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre><p>可将 display 方法提出实现。</p>
<ol start="2">
<li>性能考虑：</li>
</ol>
<ul>
<li>每次显示都重新计算合法移动，可以缓存结果</li>
<li>五子棋的胜利判断可以优化算法</li>
</ul>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token keyword keyword-private">private</span> <span class="token keyword keyword-boolean">boolean</span> <span class="token function">isFive</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword keyword-char">char</span> currentPiece <span class="token operator">=</span> currentPlayer<span class="token punctuation">.</span><span class="token function">getPiece</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> row <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> row <span class="token operator">&lt;</span> <span class="token number">8</span><span class="token punctuation">;</span> row<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> col <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> col <span class="token operator">&lt;</span> <span class="token number">8</span><span class="token punctuation">;</span> col<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>grid<span class="token punctuation">[</span>row<span class="token punctuation">]</span><span class="token punctuation">[</span>col<span class="token punctuation">]</span> <span class="token operator">!=</span> currentPiece<span class="token punctuation">)</span> <span class="token keyword keyword-continue">continue</span><span class="token punctuation">;</span>
            <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> dx <span class="token operator">=</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span> dx <span class="token operator">&lt;=</span> <span class="token number">1</span><span class="token punctuation">;</span> dx<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> dy <span class="token operator">=</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span> dy <span class="token operator">&lt;=</span> <span class="token number">1</span><span class="token punctuation">;</span> dy<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>dx <span class="token operator">==</span> <span class="token number">0</span> <span class="token operator">&amp;&amp;</span> dy <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token keyword keyword-continue">continue</span><span class="token punctuation">;</span>
                    <span class="token keyword keyword-int">int</span> count<span class="token operator">=</span><span class="token number">1</span><span class="token punctuation">;</span>
                    <span class="token keyword keyword-while">while</span> <span class="token punctuation">(</span>count<span class="token operator">&lt;=</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                        <span class="token keyword keyword-if">if</span><span class="token punctuation">(</span>count<span class="token operator">==</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                            <span class="token keyword keyword-return">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>
                        <span class="token keyword keyword-int">int</span> row_imul_count<span class="token operator">=</span>row<span class="token operator">+</span>dx<span class="token operator">*</span>count<span class="token punctuation">;</span>
                        <span class="token keyword keyword-int">int</span> col_imul_count<span class="token operator">=</span>col<span class="token operator">+</span>dy<span class="token operator">*</span>count<span class="token punctuation">;</span>
                        <span class="token keyword keyword-if">if</span><span class="token punctuation">(</span>row_imul_count<span class="token operator">&gt;=</span><span class="token number">0</span> <span class="token operator">&amp;&amp;</span> col_imul_count<span class="token operator">&gt;=</span><span class="token number">0</span><span class="token operator">&amp;&amp;</span>row_imul_count<span class="token operator">&lt;</span><span class="token number">8</span><span class="token operator">&amp;&amp;</span>col_imul_count<span class="token operator">&lt;</span><span class="token number">8</span>
                                <span class="token operator">&amp;&amp;</span>grid<span class="token punctuation">[</span>row_imul_count<span class="token punctuation">]</span><span class="token punctuation">[</span>col_imul_count<span class="token punctuation">]</span> <span class="token operator">==</span> currentPiece<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                            count<span class="token operator">++</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>
                        <span class="token keyword keyword-else">else</span> <span class="token keyword keyword-break">break</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token keyword keyword-return">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre><hr>
<h3 id="改进建议">改进建议 </h3>
<h4 id="成员一">成员一： </h4>
<ol>
<li>显示模块重构</li>
</ol>
<ul>
<li>将 <code>DisplayBoard</code> 抽象为接口，支持控制台和 GUI 两种实现。</li>
</ul>
<ol start="2">
<li>改变<code>checkWin</code>的检测逻辑或者方法，让<code>checkWin</code>能够更快的检测到玩家是否胜利。</li>
</ol>
<h4 id="成员二">成员二： </h4>
<ol>
<li>优化五子棋胜利判断</li>
</ol>
<ul>
<li>问题：当前实现效率低，检查了不必要的情况</li>
<li>改进：使用 <code>int[][] directions = {{1,0}, {0,1}, {1,1}, {1,-1}}</code> 以及加强 for 循环</li>
</ul>
<ol start="2">
<li>优化性能 - 缓存合法移动</li>
</ol>
<ul>
<li>
<p>在 ReversiBoard 中添加</p>
<ul>
<li><code>private List&lt;int[]&gt; cachedLegalMoves;</code></li>
<li><code>private Player cachedForPlayer;</code></li>
</ul>
</li>
</ul>
<hr>
<h2 id="第二部分-版本更新与迭代">第二部分 版本更新与迭代 </h2>
<h3 id="lab2-最初的版本">lab2 最初的版本 </h3>
<p><strong>代码组成</strong>：ChessGame.java<br>
<strong>设计思路</strong></p>
<ol>
<li>使用<code>static final</code>修饰和定义常量。（static 静态变量，final 不可修改）</li>
</ol>
<ul>
<li><code>private static final int BOARD_SIZE = 8;  private static final char EMPTY = '+';</code></li>
</ul>
<ol start="2">
<li>通过数组储存棋盘。</li>
</ol>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token keyword keyword-private">private</span> <span class="token keyword keyword-static">static</span> <span class="token keyword keyword-void">void</span> <span class="token function">printBoard</span><span class="token punctuation">(</span><span class="token keyword keyword-char">char</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">[</span><span class="token punctuation">]</span> board<span class="token punctuation">)</span> <span class="token punctuation">{</span>
     <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token string">"   A  B  C  D  E  F  G  H"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token constant">BOARD_SIZE</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
         <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span><span class="token punctuation">(</span>i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token string">"  "</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// 打印行坐标</span>
         <span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> j <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> j <span class="token operator">&lt;</span> <span class="token constant">BOARD_SIZE</span><span class="token punctuation">;</span> j<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
             <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">print</span><span class="token punctuation">(</span>board<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">[</span>j<span class="token punctuation">]</span> <span class="token operator">+</span> <span class="token string">"  "</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">// 有两个空格，对齐列</span>
         <span class="token punctuation">}</span>
         <span class="token class-name">System</span><span class="token punctuation">.</span>out<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
     <span class="token punctuation">}</span>
 <span class="token punctuation">}</span>
</code></pre><ol start="3">
<li>解析用户输入</li>
</ol>
<ul>
<li>通过 charAt()获取用户输入字符串 input 的第 n 个字符（索引从 0 开始）。</li>
<li>通过 toLowerCase()方法将输入的字母均改为小写。</li>
<li>对坐标进行“ - 1 ”操作，保证返回坐标与数组坐标精确对应。</li>
</ul>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token comment">// 解析用户输入，将输入转换为棋盘坐标</span>
<span class="token keyword keyword-private">private</span> <span class="token keyword keyword-static">static</span> <span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token function">parseInput</span><span class="token punctuation">(</span><span class="token class-name">String</span> input<span class="token punctuation">)</span> <span class="token punctuation">{</span>
<span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>input<span class="token punctuation">.</span><span class="token function">length</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token number">2</span><span class="token punctuation">)</span>
<span class="token keyword keyword-return">return</span> <span class="token keyword keyword-null">null</span><span class="token punctuation">;</span><span class="token comment">// 判断输入长度</span>
        <span class="token keyword keyword-char">char</span> rowChar <span class="token operator">=</span> input<span class="token punctuation">.</span><span class="token function">charAt</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 行字符</span>
        <span class="token keyword keyword-char">char</span> colChar <span class="token operator">=</span> input<span class="token punctuation">.</span><span class="token function">charAt</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 列字符</span>
        <span class="token comment">// 判断行列字符是否合规</span>
        <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>rowChar <span class="token operator">&lt;</span> <span class="token char">'1'</span> <span class="token operator">||</span> rowChar <span class="token operator">&gt;</span> <span class="token char">'8'</span><span class="token punctuation">)</span>
            <span class="token keyword keyword-return">return</span> <span class="token keyword keyword-null">null</span><span class="token punctuation">;</span>
        colChar <span class="token operator">=</span> <span class="token class-name">Character</span><span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span>colChar<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 大小写输入转换</span>
        <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>colChar <span class="token operator">&lt;</span> <span class="token char">'a'</span> <span class="token operator">||</span> colChar <span class="token operator">&gt;</span> <span class="token char">'h'</span><span class="token punctuation">)</span>
            <span class="token keyword keyword-return">return</span> <span class="token keyword keyword-null">null</span><span class="token punctuation">;</span>
        <span class="token keyword keyword-return">return</span> <span class="token keyword keyword-new">new</span> <span class="token keyword keyword-int">int</span><span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token punctuation">{</span> rowChar <span class="token operator">-</span> <span class="token char">'1'</span><span class="token punctuation">,</span> colChar <span class="token operator">-</span> <span class="token char">'a'</span> <span class="token punctuation">}</span><span class="token punctuation">;</span><span class="token comment">// 返回坐标</span>
    <span class="token punctuation">}</span>
</code></pre><p><strong>出现的问题和不足</strong></p>
<ul>
<li>仅仅设计了一个类，未考虑之后是否需要扩展。</li>
</ul>
<h3 id="lab3-通过面向对象的方式重构代码">lab3 通过面向对象的方式重构代码 </h3>
<p><strong>代码组成</strong>：Chess.java，ChessBoard.java，ChessBoardMananger.java，DisplayBoard.java，NewChessGame.java，Player.java<br>
<strong>进行的改进</strong></p>
<ol>
<li>通过面向对象的方法对程序进行了完全的重构。</li>
<li>建立了多个文件，每个文件内放一个类。全部文件放在一个包（chess_game）下。<br>
<img src="./Pre_files/lab3.png" alt="lab 3"></li>
<li>每个类各司其职，存放不同的方法与参数。</li>
</ol>
<ul>
<li>例如：<code>Chess</code>只存放棋子和棋盘大小常量。<code>DisplayBoard</code>只存放与打印棋盘相关的方法和量。</li>
</ul>
<p><strong>缺点</strong></p>
<ol>
<li>未将 peace 游戏模式抽象为单独的一个类，如果之后要进行新游戏模式的扩展时，会导致“牵一发而动全身”。比如在这次 lab 中，<br>
peace 模式的下棋方法存放在了 <code>NewChessGame </code>中，如果之后添加新的模式，很难对原有方法进行更改和处理。</li>
<li>缺失<code>GameManager</code>类，所有控制游戏行为的方法全部集中在<code>NewChessGame</code>中，导致<code>NewChessGame</code>代码过于冗杂，不利于阅读和修改。</li>
</ol>
<h3 id="lab4-新增继承与多态的概念">lab4 新增继承与多态的概念 </h3>
<p><strong>代码组成</strong>：（9 份源代码）<br>
Chess.java，ChessBoard.java，DisplayBoard.java，Game.java，GameManager.java，NewChessGame.java，PeaceGame.java，ReversiGame.java，Player.java<br>
<strong>进行的改进</strong></p>
<ol>
<li>引入了继承和多态的概念，创建了父类<code>Game</code>，子类<code>PeaceGame</code>和<code>ReversiGame</code>。</li>
<li>进一步细化了类的责任，比如<code>DisplayBoard</code>只负责打印棋盘，各个子类负责控制自己的游戏逻辑/规则、初始化各自的棋盘状态等。</li>
</ol>
<h3 id="lab5-新增五子棋模式进一步优化显示界面布局">lab5 新增五子棋模式，进一步优化显示界面布局 </h3>
<p><strong>代码组成</strong>：（）<br>
ChessBoard.java ，DisplayBoard.java，GomokuGame.java，Game.java，PeaceGame.java，ReversiGame.java，GomoKuGame.java,Player.java，NewChessGame.java，GameManager.java，</p>
<ol>
<li>添加了新的模式<code>GomokuGame</code>。</li>
<li>修改部分较为复杂的<code>if else</code>条件语句为<code>switch</code>语句，使条件判断更清晰明了。</li>
</ol>
<pre data-role="codeBlock" data-info="java" class="language-java java"><code><span class="token keyword keyword-switch">switch</span> <span class="token punctuation">(</span>mode<span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword keyword-case">case</span> <span class="token string">"peace"</span><span class="token operator">:</span>
            games<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword keyword-new">new</span> <span class="token class-name">PeaceGame</span><span class="token punctuation">(</span>player1<span class="token punctuation">,</span> player2<span class="token punctuation">,</span> newId<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword keyword-break">break</span><span class="token punctuation">;</span>
        <span class="token keyword keyword-case">case</span> <span class="token string">"reversi"</span><span class="token operator">:</span>
            games<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword keyword-new">new</span> <span class="token class-name">ReversiGame</span><span class="token punctuation">(</span>player1<span class="token punctuation">,</span> player2<span class="token punctuation">,</span> newId<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword keyword-break">break</span><span class="token punctuation">;</span>
        <span class="token keyword keyword-case">case</span> <span class="token string">"gomoku"</span><span class="token operator">:</span>
            games<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword keyword-new">new</span> <span class="token class-name">GomokuGame</span><span class="token punctuation">(</span>player1<span class="token punctuation">,</span> player2<span class="token punctuation">,</span> newId<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 支持添加Gomoku</span>
            <span class="token keyword keyword-break">break</span><span class="token punctuation">;</span>
        <span class="token keyword keyword-default">default</span><span class="token operator">:</span>
            <span class="token keyword keyword-break">break</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
</code></pre><pre data-role="codeBlock" data-info="java" class="language-java java"><code>    <span class="token comment">// 更改条件语句逻辑，采用更清晰的 switch 结构</span>

    <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>mode<span class="token punctuation">.</span><span class="token function">equalsIgnoreCase</span><span class="token punctuation">(</span><span class="token string">"peace"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    games<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword keyword-new">new</span> <span class="token class-name">PeaceGame</span><span class="token punctuation">(</span>player1<span class="token punctuation">,</span> player2<span class="token punctuation">,</span> newId<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span>

    <span class="token keyword keyword-else">else</span> <span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>mode<span class="token punctuation">.</span><span class="token function">equalsIgnoreCase</span><span class="token punctuation">(</span><span class="token string">"reversi"</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    games<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token keyword keyword-new">new</span> <span class="token class-name">ReversiGame</span><span class="token punctuation">(</span>player1<span class="token punctuation">,</span> player2<span class="token punctuation">,</span> newId<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token punctuation">}</span>
    <span class="token operator">/</span>
</code></pre><ol start="3">
<li>
<p>优化了游戏信息、列表栏的显示方式，以及输入提示词。将之移动至棋盘右方。</p>
<ul>
<li>运行效果</li>
</ul>
<pre data-role="codeBlock" data-info="" class="language-text"><code>   A  B  C  D  E  F  G  H   当前游戏: #1
1  ·  ·  ·  ·  ·  ·  ·  ·   模式: peace
2  ·  ·  ·  ·  ·  ·  ·  ·   玩家: 张三
3  ·  ·  ·  ·  ·  ·  ·  ·
4  ·  ·  ·  ○  ●  ·  ·  ·
5  ·  ·  ·  ●  ○  ·  ·  ·   游戏列表:
6  ·  ·  ·  ·  ·  ·  ·  ·   1 . peace        2 . reversi
7  ·  ·  ·  ·  ·  ·  ·  ·   3 . gomoku
8  ·  ·  ·  ·  ·  ·  ·  ·
输入示例(坐标:1A 棋盘编号：1，2 添加模式(peace(黑白棋无规则)/reversi(黑白棋有规则))/gomoku(五子棋)) 其他命令：pass(放弃此次下棋,仅限 reversi)/quit(退出游戏)。
请输入:
</code></pre></li>
<li>
<p>增加了当玩家胜利时，可自主选择继续游玩（enter），还是直接退出（quit）的选项。</p>
</li>
</ol>
<h3 id="others">others </h3>
<p><strong>使用了 git 对代码进行版本管理</strong></p>
<ol>
<li>自 lab4 开始，由于文件越来越多，越发难以记住有哪些地方是否解决了，又或者修改了那些地方，于是我尝试使用 git 进行代码的管理。
<ul>
<li>vscode 的 GitLen 插件，图形化“commit”更符合现代人使用习惯。</li>
<li>commit 每次修改都提交概要信息，下一次可以更好地进入状态。<br>
<img src="./Pre_files/版本管理.png" alt="示例"></li>
</ul>
</li>
<li>如果修改后出了 Bug 可以随时回退版本，返回修改前的版本。
<ul>
<li>git reset <commitid> # 慎用，会完全删除掉回退版本后的所有版本。</commitid></li>
<li>git revert <commitid> # 这个相当于以回退版本重新提交一次 commit。</commitid></li>
</ul>
</li>
</ol>

      </div>
      
      
    
    
    
    
    
    
  </body></html>